package com.example.service.impl;

import com.example.mapper.EmpMapper;
import com.example.mapper.OutputAllMapper;
import com.example.pojo.Emp;
import com.example.pojo.PageBean;
import com.example.pojo.Wages;
import com.example.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private OutputAllMapper outputAllMapper;
    @Override
    public PageBean page(Integer page, Integer pageSize, String name, int departmentID, LocalDate begin, LocalDate end) {
        Long count = empMapper.count(name,departmentID,begin,end);//总数返回
        Integer start=(page-1)*pageSize;//计算起始位置
        List<Emp> empList = empMapper.page(start, pageSize,name,departmentID,begin,end);//该页记录数返回

        PageBean pageBean = new PageBean(count, empList);
        return pageBean;
    }

    @Override
    public void add(Emp emp) {
        emp.setHireDate(LocalDate.now());
        empMapper.add(emp);
    }

    @Override
    public void deletes(List<Integer> ids) {
        empMapper.deletes(ids);
    }

    @Override
    public void update(Emp emp) {
        empMapper.update(emp);
    }

    @Override
    public List<Emp> select() {
        List<Emp> empList = empMapper.select();
        return empList;
    }

    @Override
    public void wages_get(Wages wages) {
        LocalDate currentDate = LocalDate.now();
        // 获取月份
        int month = currentDate.getMonthValue();
        String month_now=month+"月";
        wages.setMonth(month_now);
        String ss="工资发放"+wages.getEmpname()+"的"+wages.getMonth()+"工资";
        outputAllMapper.add(ss,wages.getWages(),currentDate);
        empMapper.set_wages(wages);
    }

    @Override
    public String selects() {
        List<Emp> empList=empMapper.selectss();
        String s="";
        for (int i = 0; i < empList.size(); i++) {
            s+=empList.get(i).getName()+",";
        }
        return s;
    }
}
